package org.springblade.tms.config;

import com.dtp.common.em.QueueTypeEnum;
import com.dtp.common.em.RejectedTypeEnum;
import com.dtp.core.thread.DtpExecutor;
import com.dtp.core.thread.ThreadPoolBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author: wzq
 * @className: ThreadPoolConfig
 * @createDate: 2022/3/18
 * @description: 线程池相关配置
 */
@Configuration
public class ThreadPoolConfig {

	@Bean
	public ThreadPoolExecutor dynamicTp() {
		DtpExecutor exe = ThreadPoolBuilder.newBuilder()
			.threadPoolName("dynamicTp")
			.corePoolSize(8)
			.maximumPoolSize(16)
			.keepAliveTime(50)
			.allowCoreThreadTimeOut(true)
			.workQueue(QueueTypeEnum.SYNCHRONOUS_QUEUE.getName(), null, false)
			.rejectedExecutionHandler(RejectedTypeEnum.CALLER_RUNS_POLICY.getName())
			.threadFactory("DTP-线程")
			.buildDynamic();
		return exe;
	}
}
